/*
 * Created by JFormDesigner on Fri Mar 08 09:33:41 CST 2019
 */

package com.n9.qqonline.sales.view;

import com.n9.qqonline.sales.service.FormService;

import javax.swing.*;
import javax.swing.border.EmptyBorder;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

/**
 * @author Brainrain
 */
public class AddAccountForm extends JDialog implements ActionListener {
    private static final AddAccountForm me = new AddAccountForm((Frame)null);

    public static AddAccountForm instance() {
        return me;
    }

    private AddAccountForm(Frame owner) {
        super(owner);
        initComponents();
    }

    private AddAccountForm(Dialog owner) {
        super(owner);
        initComponents();
    }

    @Override
    public void actionPerformed(ActionEvent e) {
        new FormService().doActionPerformed(e);
    }

    /**
     * 获取账号
     * @return
     */
    public String getAccountsString() {
        return this.accountsTextArea.getText();
    }

    /**
     * 清空账号
     */
    public void clearAccounts() {
        SwingUtilities.invokeLater(()->{
            this.accountsTextArea.setText("");
        });
    }


    private void initComponents() {
        // JFormDesigner - Component initialization - DO NOT MODIFY  //GEN-BEGIN:initComponents
        dialogPane = new JPanel();
        contentPanel = new JPanel();
        label1 = new JLabel();
        scrollPane1 = new JScrollPane();
        accountsTextArea = new JTextArea();
        buttonBar = new JPanel();
        okBtn = new JButton();
        cancelBtn = new JButton();

        //======== this ========
        setTitle("addAccount");
        setModal(true);
        Container contentPane = getContentPane();
        contentPane.setLayout(new BorderLayout());

        //======== dialogPane ========
        {
            dialogPane.setBorder(new EmptyBorder(12, 12, 12, 12));
            dialogPane.setPreferredSize(new Dimension(500, 300));
            dialogPane.setLayout(new BorderLayout());

            //======== contentPanel ========
            {
                contentPanel.setLayout(new BorderLayout());

                //---- label1 ----
                label1.setText("\u8d26\u53f7----\u5bc6\u7801\uff0c\u5206\u5272\u7b26\u4e3a4\u4e2a\u6a2a\u6760\uff0c\u4e00\u884c\u4e3a\u4e00\u4e2a\u8d26\u53f7");
                label1.setPreferredSize(new Dimension(500, 30));
                contentPanel.add(label1, BorderLayout.SOUTH);

                //======== scrollPane1 ========
                {
                    scrollPane1.setViewportView(accountsTextArea);
                }
                contentPanel.add(scrollPane1, BorderLayout.CENTER);
            }
            dialogPane.add(contentPanel, BorderLayout.CENTER);

            //======== buttonBar ========
            {
                buttonBar.setBorder(new EmptyBorder(12, 0, 0, 0));
                buttonBar.setLayout(new GridBagLayout());
                ((GridBagLayout)buttonBar.getLayout()).columnWidths = new int[] {0, 85, 80};
                ((GridBagLayout)buttonBar.getLayout()).columnWeights = new double[] {1.0, 0.0, 0.0};

                //---- okBtn ----
                okBtn.setText("OK");
                okBtn.setActionCommand("ADD_ACCOUNT_OK");
                buttonBar.add(okBtn, new GridBagConstraints(1, 0, 1, 1, 0.0, 0.0,
                    GridBagConstraints.CENTER, GridBagConstraints.BOTH,
                    new Insets(0, 0, 0, 5), 0, 0));

                //---- cancelBtn ----
                cancelBtn.setText("Cancel");
                cancelBtn.setActionCommand("ADD_ACCOUNT_CANCEL");
                buttonBar.add(cancelBtn, new GridBagConstraints(2, 0, 1, 1, 0.0, 0.0,
                    GridBagConstraints.CENTER, GridBagConstraints.BOTH,
                    new Insets(0, 0, 0, 0), 0, 0));
            }
            dialogPane.add(buttonBar, BorderLayout.SOUTH);
        }
        contentPane.add(dialogPane, BorderLayout.CENTER);
        pack();
        setLocationRelativeTo(getOwner());
        // JFormDesigner - End of component initialization  //GEN-END:initComponents

        okBtn.addActionListener(this);
        cancelBtn.addActionListener(this);
    }

    // JFormDesigner - Variables declaration - DO NOT MODIFY  //GEN-BEGIN:variables
    private JPanel dialogPane;
    private JPanel contentPanel;
    private JLabel label1;
    private JScrollPane scrollPane1;
    private JTextArea accountsTextArea;
    private JPanel buttonBar;
    private JButton okBtn;
    private JButton cancelBtn;
    // JFormDesigner - End of variables declaration  //GEN-END:variables
}
